const demo = require(process.argv[2])
console.log('running', demo)

try {
    demo.throw(1)
} catch (e) {
    console.log("\ne1:", e)
}

try {
    demo.throw_error()
} catch (e) {
    console.log("\ne2:", e)
}

try {
    demo.throw_error(3)
} catch (e) {
    console.log("\ne3:", e)
}

try {
    demo.throw_error("4")
} catch (e) {
    console.log("\ne4:", e)
}

try {
    demo.throw_error("4", 5)
} catch (e) {
    console.log("\ne5:", e)
}

try {
    demo.throw_error("4", "6")
} catch (e) {
    console.log("\ne6:", e)
}

try {
    demo.throw_type_error("7", "_7_")
} catch (e) {
    console.log("\ne7:", e)
}

try {
    demo.throw_range_error("_8_", "8")
} catch (e) {
    console.log("\ne8:", e)
}

console.log("\ne9:", demo.create_error("99", "9"))
console.log("\ne10:", demo.create_type_error("10", "1010"))
console.log("\ne11:", demo.create_range_error("1111", "11"))

demo.catch_inner_exception()
demo.fatal_error()

/*
running {
  throw: [Function (anonymous)],
  throw_error: [Function (anonymous)],
  throw_type_error: [Function (anonymous)],
  throw_range_error: [Function (anonymous)],
  create_error: [Function (anonymous)],
  create_type_error: [Function (anonymous)],
  create_range_error: [Function (anonymous)],
  catch_inner_exception: [Function (anonymous)],
  fatal_error: [Function (anonymous)]
}

e1: 1

e2: Error: no_mesg
    at Object.<anonymous> (/home/luwh/repo/demos/third_party_demo/napi/src/14.fatal_exception.js:11:10)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'no_code'
}

e3: Error: A string was expected at 1st parameter
    at Object.<anonymous> (/home/luwh/repo/demos/third_party_demo/napi/src/14.fatal_exception.js:17:10)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47

e4: Error: no_mesg
    at Object.<anonymous> (/home/luwh/repo/demos/third_party_demo/napi/src/14.fatal_exception.js:23:10)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: '4'
}

e5: Error: A string was expected at 2nd parameter
    at Object.<anonymous> (/home/luwh/repo/demos/third_party_demo/napi/src/14.fatal_exception.js:29:10)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47

e6: Error: 6
    at Object.<anonymous> (/home/luwh/repo/demos/third_party_demo/napi/src/14.fatal_exception.js:35:10)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: '4'
}

e7: TypeError: _7_
    at Object.<anonymous> (/home/luwh/repo/demos/third_party_demo/napi/src/14.fatal_exception.js:41:10)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: '7'
}

e8: RangeError: 8
    at Object.<anonymous> (/home/luwh/repo/demos/third_party_demo/napi/src/14.fatal_exception.js:47:10)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: '_8_'
}

e9: Error: 9
    at Object.<anonymous> (/home/luwh/repo/demos/third_party_demo/napi/src/14.fatal_exception.js:52:27)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: '99'
}

e10: TypeError: 1010
    at Object.<anonymous> (/home/luwh/repo/demos/third_party_demo/napi/src/14.fatal_exception.js:53:28)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: '10'
}

e11: RangeError: 11
    at Object.<anonymous> (/home/luwh/repo/demos/third_party_demo/napi/src/14.fatal_exception.js:54:28)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: '1111'
}
I CatchInnerException +168 pending: 'false'
I CatchInnerException +180 pending: 'true'
I CatchInnerException +181 isError: 'false'
I CatchInnerException +192 pending: 'true'
I CatchInnerException +193 isError: 'true'
FATAL ERROR: location message
 1: 0x561dc55ca2f5 node::Abort() [node]
 2: 0x561dc546448f node::OnFatalError(char const*, char const*) [node]
 3: 0x561dc54644b4  [node]
 4: 0x561dc5591087 napi_fatal_error [node]
 5: 0x7eff5c3243e2  [/home/luwh/repo/demos/build/out/clang/libs/libnapi.14.fatal_exception.node]
 6: 0x561dc556e80f  [node]
 7: 0x561dc58221c8 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [node]
 8: 0x561dc5822972  [node]
 9: 0x561dc582312c v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
10: 0x561dc60f9639  [node]
[1]    2545371 IOT instruction (core dumped)  ./out/napi.14.fatal_exception
*/
